﻿using System;
using System.Text;

namespace dotHTML.HTML {
    /// <summary>
    /// Represents a collection of fields within a web form.
    /// </summary>
    [Serializable]
    public class FieldSet : Element {
        private bool _disabled;
        private Form _form;
        private string _name;

        /// <summary>
        /// Determines whether or not this control is disabled.
        /// </summary>
        public bool Disabled {
            get { return _disabled; }
            set { _disabled = value; }
        }

        /// <summary>
        /// Determines the parent form of this FieldSet.
        /// </summary>
        public Form Form {
            get { return _form; }
            set { _form = value; }
        }

        /// <summary>
        /// Determines the name associated with the group.
        /// </summary>
        public string Name {
            get { return _name; }
            set { _name = value; }
        }

        /// <summary>
        /// Gets a formatted string of all local attributes of this element
        /// (not including the base attributes).
        /// </summary>
        /// <param name="sb">The StringBuilder to write this element's
        /// attribute data to.</param>
        protected override void WriteLocalAttributes(StringBuilder sb) {
            AttributeWriter.Write(sb, _disabled, "disabled");
            if (_form != null) {
                AttributeWriter.Write(sb, _form.ID, "form");
            }
            AttributeWriter.Write(sb, _name, "name");
        }
    }
}
